package net.yxsoft.service.common;

import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;
import net.yxsoft.bean.BSTablePage;
import net.yxsoft.model.infrastructure.TsLog;
import net.yxsoft.resource.CodeRes;
import rapid.core.Authuser;

import java.util.List;

public abstract class BaseService extends rapid.jfinal.BaseService {

  /**
  * @MethodName: findByTsCodes
  * @Description: 
  * @param: codeType
  * @return * @return java.util.List<com.jfinal.plugin.activerecord.Record>
  * @throws 
  * @date 2023/8/31 13:40
  * @author wj 
  */
  public List<Record> findByTsCodes(String codeType){

      return Db.find("select customid,codename from ts_code where leaf = 2 and enabled = 1 and codetype = ? order by sortno", codeType);
  }
  

  /**
  * @MethodName: log
  * @Description: 用户操作日志
  * @param: user 用户
   * @param: appName 应用程序名称
   * @param: operate 用户操作，例如"添加"，"更新"
   * @param: ip 客户端IP
   * @param: desc  具体操作内容描述，例如"单据号：BX3302384"
  * @return * @return void
  * @throws
  * @date 2023/8/31 13:42
  * @author wj
  */
  @SuppressWarnings("unchecked")
  protected void log(Authuser user, String appName, String operate, String ip, String desc) {
    log(user.getLoginId(), user.getName(), appName, operate, ip, desc);
  }

  /**
  * @MethodName: log
  * @Description:  用户操作日志
  * @param: loginId 用户的登录账号（注意，不是主键值）
   * @param: userName 账号称
   * @param: appName 应用程序名称
   * @param: operate 用户操作，例如"添加"，"更新"
   * @param: ip 客户端IP
   * @param: desc 具体操作内容描述，例如"单据号：BX3302384"
  * @return * @return void
  * @throws
  * @date 2023/8/31 13:42
  * @author wj
  */
  @SuppressWarnings("unchecked")
  protected void log(String loginId, String userName, String appName, String operate, String ip, String desc) {
    TsLog log = new TsLog();
    log.setLogId(null);
    log.setOperatorLoginId(loginId);
    log.setOperatorName(userName);
    log.setModel(appName);
    log.setOperate(operate);
    log.setOperateTime(new java.sql.Date(new java.util.Date().getTime()));
    log.setContent(desc);
    log.setIp(ip);
    log.save();
  }
}
